package fun.codefarmer.pm.service.Impl;

import fun.codefarmer.pm.mapper.PositionMapper;
import fun.codefarmer.pm.model.Position;
import fun.codefarmer.pm.model.RespBean;
import fun.codefarmer.pm.service.PositionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ ClassName PositionServiceImpl
 * @ Descriotion TODO
 * @ author  codeFarmer_z
 * @ 公众号：码农教程
 * @ Date 2022/4/18 17:34
 **/
@Service
public class PositionServiceImpl implements PositionService {
    @Resource
    private PositionMapper positionMapper;

    @Override
    public RespBean addPosition(Position position) {
        position.setEnabled(true);
        position.setCreateDate(new Date());
        // 插入方法中不存id，数据库自动自增
        int insert = positionMapper.insertSelective(position);
        if (insert == 1) {
            return RespBean.ok("职位添加成功");
        }
        return RespBean.ok("添加失败");
    }

    @Override
    public List<Position> getAllPosition() {
        List<Position> positions = positionMapper.getAllPosition();
        return positions;
    }

    @Override
    public RespBean updatePosition(Position position) {
        if (positionMapper.updateByPrimaryKeySelective(position) ==1) {
            return RespBean.ok("修改成功");
        }
        return RespBean.error("修改失败");
    }

    @Override
    public RespBean deletePosition(Integer id) {
        if (positionMapper.deleteByPrimaryKey(id) ==1) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @Override
    public RespBean deletePositionByIds(Integer[] ids) {
        if (positionMapper.deletePositionByIds(ids) == ids.length) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
